//
//  AYMPerosnalMSGView.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/8.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMPerosnalMSGView.h"

@interface AYMPerosnalMSGView ()

@property (nonatomic,weak) UIView *alertView;


@end

@implementation AYMPerosnalMSGView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
    
    [self setupCoverView];
    //白色弹框
    UIView *alertView = [[UIView alloc]init];
    self.alertView = alertView;
    alertView.layer.cornerRadius = 10;
    alertView.clipsToBounds = YES;
    alertView.backgroundColor = [UIColor whiteColor];
    [self addSubview:alertView];
    [alertView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(25);
        make.width.equalTo(300);
        make.height.equalTo(200);
    }];
    //弹框顶部label
    UILabel *topLabel = [UILabel textColor:commonTextColor font:personalCellFont];
    self.topLabel = topLabel;
    [alertView addSubview:topLabel];
    topLabel.text = @"设置身高(cm)";
    topLabel.textAlignment = NSTextAlignmentCenter;
    [topLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(alertView);
        make.top.equalTo(alertView).offset(25);
 
    }];
    //分隔线
    UIView *lineViewH = [[UIView alloc]init];
    lineViewH.backgroundColor = [UIColor lightGrayColor];
    [alertView addSubview:lineViewH];
    [lineViewH makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(alertView);
        make.height.equalTo(1);
        make.bottom.equalTo(alertView).offset(-55);
    }];
    
    //取消按钮
    UIButton *cancelBtn = [UIButton titleName:@"取消" NormalColor:[UIColor grayColor] font:personalCellFont];
    [cancelBtn addTarget:self action:@selector(didClickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:cancelBtn];
    [cancelBtn makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.equalTo(alertView);
        make.width.equalTo(150);
        make.height.equalTo(55);
    }];
    //提交按钮
    UIButton *commitBtn = [UIButton titleName:@"提交" NormalColor:commonTextColor font:personalCellFont];
    [commitBtn addTarget:self action:@selector(didClickCommitBtn) forControlEvents:UIControlEventTouchUpInside];
    commitBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:commitBtn];
    [commitBtn makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.bottom.equalTo(alertView);
        make.width.height.equalTo(cancelBtn);
    }];
    //两个按钮中间的分隔线
    UIView *lineViewV = [[UIView alloc]init];
    lineViewV.backgroundColor = [UIColor lightGrayColor];
    [alertView addSubview:lineViewV];
    [lineViewV makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(1);
        make.height.equalTo(20);
        make.centerX.equalTo(alertView);
        make.bottom.equalTo(alertView).offset(-18);
        
    }];
    //pickerView
    UIPickerView *pickView = [[UIPickerView alloc]init];
    self.pickView = pickView;
    [alertView addSubview:pickView];
    [pickView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(alertView);
        make.width.equalTo(160);
        make.height.equalTo(60);
        make.top.equalTo(60);
    }];
    
}

#pragma mark - 按钮点击事件
-(void)didClickCancelBtn{
    
    if ([self.delegate respondsToSelector:@selector(perosnalMSGViewCancelBtn:)]) {
        [self.delegate perosnalMSGViewCancelBtn:self];
    }
}

-(void)didClickCommitBtn{

    if ([self.delegate respondsToSelector:@selector(perosnalMSGView:)]) {
        [self.delegate perosnalMSGView:self];
    }

}

#pragma mark - 设置coverView
-(void)setupCoverView{
    
    UIView* coverView = [[UIView alloc] initWithFrame:self.bounds];
    coverView.backgroundColor = [UIColor blackColor];
    coverView.alpha = 0.3;
    [self addSubview:coverView];
    
}
@end
